package bavaria.hightec.time;



	import java.awt.Graphics;
	import java.util.TimerTask;
	import java.util.Timer;
	import java.util.Calendar;
	import java.util.Date;
	import java.text.DateFormat;
	import java.awt.Font;
	import javax.swing.JFrame;
	import javax.swing.JPanel;

	public class Clock extends JFrame {
	    private static final int TICK_PERIOD = 1000;
	    private Timer ticker;
	    private JPanel panel;
	    private static Calendar cal;

	    private class TickerTask extends TimerTask {
	        public void run() {
	            panel.repaint();
	        }
	    }

	    private static class ClockDisplay extends JPanel {
	        @Override
	        public void paintComponent(Graphics g) {
	            super.paintComponent(g);
	            Date date = cal.getTime();
	            DateFormat dateFormatter = DateFormat.getTimeInstance();
	            g.setFont(new Font(null,Font.PLAIN,20));
	            g.drawString(dateFormatter.format(date), 20, 50);
	            dateFormatter = DateFormat.getDateInstance();
	            g.drawString(dateFormatter.format(date), 10, 30);
	        }
	    }


	    public Clock(Timer timer,Calendar cal) {
	        panel = new ClockDisplay();
	        add("Center", panel);
	        setDefaultCloseOperation(EXIT_ON_CLOSE);
	        setSize(130, 100);
	        setVisible(true);
	        this.cal = cal;
	        ticker = timer;
	        start();

	    }

	    public void start() {
	        ticker.scheduleAtFixedRate(new TickerTask(), 0, TICK_PERIOD);
	    }
	}

